feat: add BINARY_TEST_MODE to testkit for real binary testing#394
feat: add BINARY_TEST_MODE to testkit for real binary testing#394
Conversation
When BINARY_TEST_MODE=1, the testkit: - Starts a real Express HTTP server (BinaryAPIServer) instead of MSW - Spawns bin/run.js via execa with BASE44_API_URL pointing at the server - Skips MSW server lifecycle in setupCLITests() All 21 existing test spec files are unchanged — the TestContext interface is fully preserved. The migration requires only setting BINARY_TEST_MODE=1. Co-authored-by: Kfir Stri <kfirstri@users.noreply.github.com>
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/cli@0.0.41-pr.394.67fd14dPrefer not to change any import paths? Install using npm alias so your code still imports npm i "base44@npm:@base44-preview/cli@0.0.41-pr.394.67fd14d"Or add it to your {
"dependencies": {
"base44": "npm:@base44-preview/cli@0.0.41-pr.394.67fd14d"
}
}
Preview published to npm registry — try new features instantly! |
|
|
Claude finished @kfirstri's task in 7m 42s —— View job Changes complete
What changed
|
- Remove BINARY_TEST_MODE env var — binary mode is now the only mode - Replace `node bin/run.js` with the platform-specific compiled binary from `dist/binaries/` (produced by `bun run build:binaries`) - Add `mockRoute()` to BinaryAPIServer for custom/stateful Express handlers - Remove unused `port` getter and `mockError` method (fixes knip errors) - Remove in-process (MSW) test path and related helpers from CLITestkit - Remove MSW lifecycle hooks (mswServer) from testkit index - Rewrite authorization.spec.ts to use BinaryAPIServer.mockRoute() instead of mswServer for the token-refresh-on-401 scenarios Co-authored-by: Kfir Stri <kfirstri@users.noreply.github.com>
@claude now i see these errors: in typecheck: All tests seems to fail, something with the toContain |
|
Claude finished @kfirstri's task in 11s —— View job Changes complete
Root causes explainedTypeCheck error: Test failures (empty stdout/stderr, exit code 1): Commander.js only intercepts errors with
|
- Delete Base44APIMock.ts (dead code, no tests use it); fixes typecheck error from mswServer import that no longer exists in index.ts - Remove msw from devDependencies since it was only used by Base44APIMock - Fix secrets set preAction hook to call command.error() instead of throwing, so Commander.js outputs the error to stderr when no args are provided - Fix logs --limit option parser to throw InvalidArgumentError (Commander type) instead of InvalidInputError, so Commander.js properly intercepts and displays it - Add tests/globalSetup.ts that auto-builds the binary if dist/binaries/ is missing - Add globalSetup to vitest.config.ts so CI never runs tests without a binary Fixes: typecheck error (mswServer), 2 failing tests (empty output on validation errors) Co-authored-by: Kfir Stri <kfirstri@users.noreply.github.com>
Made-with: Cursor # Conflicts: # packages/cli/tests/cli/testkit/Base44APIMock.ts
Reverts the change from InvalidArgumentError (Commander.js) back to InvalidInputError (project's error class) in the --limit option parser. Co-authored-by: Kfir Stri <kfirstri@users.noreply.github.com>
Reverts command.error() back to throwing InvalidInputError, restoring original behavior for input validation in the preAction hook. Co-authored-by: Kfir Stri <kfirstri@users.noreply.github.com>
Users are responsible for running bun run build and bun run build:binaries before tests. Co-authored-by: Kfir Stri <kfirstri@users.noreply.github.com>
…private helper Co-authored-by: Kfir Stri <kfirstri@users.noreply.github.com>
Co-authored-by: Kfir Stri <kfirstri@users.noreply.github.com>
Co-authored-by: Kfir Stri <kfirstri@users.noreply.github.com>
Note
Description
Replaces MSW (Mock Service Worker) with a real lightweight Express HTTP server (
TestAPIServer) for CLI integration tests. This approach exercises the full CLI pipeline — including subprocess spawning, argument parsing, and actual HTTP calls — making tests more faithful to real-world behavior. It also adds support for running the full test suite against the compiled standalone binary (in addition to the npm bundle), and wires both modes into CI via a matrix strategy.Related Issue
Closes #391
Type of Change
Changes Made
Base44APIMock.ts(MSW-based in-process mock) withTestAPIServer.ts(real Express HTTP server on a random port)CLI_TEST_RUNNERenv var toCLITestkitto toggle betweennpmmode (node bin/run.js) andbinarymode (compiled standalone binary)bun run test:npmandbun run test:binaryscripts topackage.jsonnpmandbinarytest modes in parallel via a matrix strategymswfrom devDependenciesdocs/testing.mdanddocs/AGENTS.mdto reflect the new testkit architecture and runner modestoHaveExitCode/toContainInStdout/toContainInStderrfrom testkit API docs (simplified totoContain)Testing
npm test)Checklist
docs/(AGENTS.md) if I made architectural changesAdditional Notes
The
TestAPIServerapproach means tests no longer depend on MSW's service worker mechanism, which had limitations when the CLI runs as a child process. Each test gets its own Express server on a random port; the CLI is pointed at it viaBASE44_API_URL. Binary mode requiresbun run build:binariesbefore runningbun run test:binary.🤖 Generated by Claude | 2026-03-10 00:00 UTC